import { defineStore } from 'pinia';

export const mainStore = defineStore('main', {
    state: () => ({
        isCollapse: JSON.parse(localStorage.getItem('isCollapse')) ?? false,  // 从localStorage获取或默认值
        asideWidth: Number(localStorage.getItem('asideWidth')) || 200,  // 从localStorage获取或默认值
        openFilePath:""
    }),
    actions: {
        changeCollapse() {
            this.isCollapse = !this.isCollapse; // 切换状态
            localStorage.setItem('isCollapse', JSON.stringify(this.isCollapse));  // 保存到localStorage
        },
        changeAsideWidth() {
            this.asideWidth = this.asideWidth === 200 ? 60 : 200; // 切换数值
            localStorage.setItem('asideWidth', String(this.asideWidth));  // 保存到localStorage
        },
        setOpenFilePath(openFilePath) {
            this.openFilePath = openFilePath;
        },
    }
});